//
//  ViewController.m
//  阿里星球-音乐界面
//
//  Created by mafeng on 16/8/14.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"
#import "PhoneRecordShopTableViewCell.h"
#import "HitMusicTableViewCell.h"
#import "ExclusiveZoneTableViewCell.h"
#import "HotSongTableViewCell.h"
#import "NewSongTableViewCell.h"
#import "IconTableViewCell.h"
#import "HitSingerTableViewCell.h"
#import "AFNetworking.h"
#import "earthModel.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) earthModel *result;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self handleData];
    
}

- (void)handleData {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *url = @"http://api.dongting.com/frontpage/frontpage?location=0&version=1470998222737&app=ttpod&v=v9.0.4.2016070616&user_id=0&mid=iPhone8%2C1&f=f320&s=s310&imsi=&hid=&splus=10.0&active=1&net=2&openudid=4bbd8925c4a3991ee51c9cd8b9a8dc5961820764&idfa=2BBAE4F7-2E3B-41AA-AE0C-F91FB2BDC279&utdid=V62kivWPJBYDABK%2FL8gCUnDI&alf=(null)&bundle_id=com.ttpod.music&latitude=(null)&longtitude=(null)&access_token=(null)&vc=9000400";
    [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        self.result = [earthModel modelWithDic:responseObject];
        NSLog(@"❤️%@", _result);
        [_tableView reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
    
    
}


// tableView 的协议方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 7;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 100;
    } else if (indexPath.section == 1) {
        return 150;
    } else if (indexPath.section == 2) {
        return 150;
    } else if (indexPath.section == 3) {
        return 320;
    } else if (indexPath.section == 4) {
        return 280;
    } else if (indexPath.section == 5) {
       return 150;
    } else if (indexPath.section == 6) {
       return 500;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        IconTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse1"];
        cell.backgroundColor = [UIColor yellowColor];
        cell.data = _result.data[1];
        return cell;
    } else if (indexPath.section == 1) {
        HitMusicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse2"];
        cell.data = _result.data[2];
        return  cell;
    } else if (indexPath.section == 2) {
        NewSongTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse3"];
        cell.data = _result.data[3];
        return cell;
    } else if (indexPath.section == 3) {
        PhoneRecordShopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse4"];
        cell.data = _result.data[4];
        return cell;
    } else if (indexPath.section == 4) {
        HotSongTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse5"];
        cell.data = _result.data[5];
        return cell;
    } else if (indexPath.section == 5) {
        HitSingerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse6"];
        cell.data = _result.data[6];
        return cell;
    } else if (indexPath.section == 6) {
        ExclusiveZoneTableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse7"];
        NSLog(@"❤️❤️:%@", _result.data);
        cell.data = _result.data[7];
        return cell;
    }
    
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.backgroundColor = [UIColor blackColor];
    label.center = CGPointMake(self.view.bounds.size.width / 2, 20);
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    if (section == 1) {
       label.text = @"歌曲推荐";
    } else if (section == 2) {
       label.text = @"新歌新碟";
    } else if (section == 3) {
       label.text = @"手机唱片店";
    } else if (section == 4) {
       label.text = @"热门歌曲";
    } else if (section == 5) {
       label.text = @"推荐艺人";
    } else if (section == 6) {
      label.text = @"独家专区";
    }
    return label;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
